import requests

url = 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'

# 防止反爬
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
}

# resp.text 字符串数据
# resp.content 二进制数据
resp = requests.get(url, headers=headers)
# 将二进制文件写入文件
with open('logo.png', 'wb') as file:
    file.write(resp.content)